<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <title>用户列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="resources/layui/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="resources/layui/css/index.css" media="all" />
</head>
<body class="childrenBody">
<!--修改密码-->
<form class="layui-form" style="width: 100%;" id="dataFrm">
    <div style="margin-top: 2%">
        <div>
            <h1 align="center" style="color:red"><strong>温馨提示</strong></h1><br>
            <h3 style="margin-left:5%">尊敬的用户：为了您的账户安全，建议将密码修改为英文字符+数字的组合形式。
            </h3><br><br>
        </div>
        <input type="hidden" name="id" id="id" value=""/>
        <div class="layui-form-item">
            <label class="layui-form-label">用户名<font color="red">*</font></label>
            <div class="layui-input-block">
                <input type="text" id="rname" name="rname" disabled="" th:value="${session.USER_SESSION.rname}" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">原密码<font color="red">*</font></label>
            <div class="layui-input-block">
                <input type="password" id="oldPwd" name="oldPwd"
                       lay-verify="oldPwd" placeholder="请填写原密码" autocomplete="off"
                       class="layui-input" maxlength="14">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">新密码<font color="red">*</font></label>
            <div class="layui-input-block">
                <input type="password" id="newPwd" name="newPwd"
                       lay-verify="newPwd" placeholder="请填写新密码" autocomplete="off"
                       class="layui-input" maxlength="14">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">确认密码<font color="red">*</font></label>
            <div class="layui-input-block">
                <input type="password" id="confirmPwd" name="confirmPwd"
                       lay-verify="confirmPwd" placeholder="请填写确认密码" autocomplete="off"
                       class="layui-input" maxlength="14">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="changePwd">立即修改</button>
                <button type="reset" class="layui-btn layui-btn-primary">取消</button>
            </div>
        </div>
    </div>
</form>
<script type="text/javascript" src="resources/layui/layui/layui.js"></script>
<script th:inline="none">
    layui.use(['form','jquery','layer'],function(){
        var form = layui.form,
            $ = layui.jquery,
            layer = layui.layer;

        //添加验证规则
        form.verify({
            newPwd : function(value, item){
                if(value.length < 6){
                    return "密码长度不能小于6位";
                }
            },
            confirmPwd : function(value, item){
                if(!new RegExp($("#newPwd").val()).test(value)){
                    return "两次输入密码不一致，请重新输入！";
                }
            }
        });
        form.on("submit(changePwd)",function(data){
            $.post("users/updatePassword",data.field,function(res){
                // console.log("*****"+data.field+"*****");
                if(res.code==4010){
                    layer.msg(res.msg,{"time":1000},function() {
                        sessionStorage.clear();
                        localStorage.clear();
                        parent.location.href="/login.html"
                    })
                }else if(res.code=-4010){
                    layer.msg(res.msg);
                }else if(res.code=-4012){
                    layer.msg(res.msg);
                }else if(res.msg=-4013){
                    layer.msg(res.msg);
                }
            });
            return false; //防止表单提交
        });
    });
</script>
</body>
</html>